/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.GeneralTest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Degreeprogram.findAll", query = "SELECT d FROM Degreeprogram d"),
    @NamedQuery(name = "Degreeprogram.findByIdentifier", query = "SELECT d FROM Degreeprogram d WHERE d.identifier = :identifier"),
    @NamedQuery(name = "Degreeprogram.findBySeqNum", query = "SELECT d FROM Degreeprogram d WHERE d.seqNum = :seqNum"),
    @NamedQuery(name = "Degreeprogram.findByDescription", query = "SELECT d FROM Degreeprogram d WHERE d.description = :description"),
    @NamedQuery(name = "Degreeprogram.findByDepartment", query = "SELECT d FROM Degreeprogram d WHERE d.department = :department"),
    @NamedQuery(name = "Degreeprogram.findBySurveyIdentifier", query = "SELECT d FROM Degreeprogram d WHERE d.surveyIdentifier = :surveyIdentifier"),
    @NamedQuery(name = "Degreeprogram.findByCourseinfoIdentifier", query = "SELECT d FROM Degreeprogram d WHERE d.courseinfoIdentifier = :courseinfoIdentifier")})
public class Degreeprogram implements Serializable, GeneralEntity {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String identifier;
    private Integer seqNum;
    @Size(max = 120)
    @Column(length = 120)
    private String description;
    @Size(max = 20)
    @Column(length = 20)
    private String department;
    private Integer surveyIdentifier;
    @Size(max = 20)
    @Column(length = 20)
    private String courseinfoIdentifier;
    @JoinTable(name = "surveytodegree", joinColumns = {
        @JoinColumn(name = "degreeprogram", referencedColumnName = "identifier", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "surveyIdentifier", referencedColumnName = "identifier", nullable = false)})
    @ManyToMany
    private Collection<Survey> surveyCollection;
    @ManyToMany(mappedBy = "degreeprogramCollection")
    private Collection<Minute> minuteCollection;
    @JoinTable(name = "coursetodegree", joinColumns = {
        @JoinColumn(name = "degreeprogram", referencedColumnName = "identifier", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "course", referencedColumnName = "identifier", nullable = false)})
    @ManyToMany
    private Collection<Courseinfo> courseinfoCollection;
    @JoinTable(name = "usertodegree", joinColumns = {
        @JoinColumn(name = "degreeprogram", referencedColumnName = "identifier", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "username", referencedColumnName = "username", nullable = false)})
    @ManyToMany
    private Collection<Users> usersCollection;
    @OneToMany(mappedBy = "degreeprogram")
    private Collection<Studentoutcome> studentoutcomeCollection;
    @OneToMany(mappedBy = "degreeProgramString")
    private Collection<Peo> peoCollection;

    public Degreeprogram() {
        this.minuteCollection = new ArrayList();
        this.courseinfoCollection = new ArrayList();
        this.peoCollection = new ArrayList();
        this.studentoutcomeCollection = new ArrayList();
        this.surveyCollection = new ArrayList();
        this.usersCollection = new ArrayList();
    }

    public Degreeprogram(String identifier) {
        this.identifier = identifier;
        this.minuteCollection = new ArrayList();
        this.courseinfoCollection = new ArrayList();
        this.peoCollection = new ArrayList();
        this.studentoutcomeCollection = new ArrayList();
        this.surveyCollection = new ArrayList();
        this.usersCollection = new ArrayList();
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public Integer getSeqNum() {
        return seqNum;
    }

    public void setSeqNum(Integer seqNum) {
        this.seqNum = seqNum;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public Integer getSurveyIdentifier() {
        return surveyIdentifier;
    }

    public void setSurveyIdentifier(Integer surveyIdentifier) {
        this.surveyIdentifier = surveyIdentifier;
    }

    public String getCourseinfoIdentifier() {
        return courseinfoIdentifier;
    }

    public void setCourseinfoIdentifier(String courseinfoIdentifier) {
        this.courseinfoIdentifier = courseinfoIdentifier;
    }

    @XmlTransient
    public Collection<Survey> getSurveyCollection() {
        return surveyCollection;
    }

    public void setSurveyCollection(Collection<Survey> surveyCollection) {
        this.surveyCollection = surveyCollection;
    }

    @XmlTransient
    public Collection<Minute> getMinuteCollection() {
        return minuteCollection;
    }

    public void setMinuteCollection(Collection<Minute> minuteCollection) {
        this.minuteCollection = minuteCollection;
    }

   
    @XmlTransient
    public Collection<Courseinfo> getCourseinfoCollection() {
        return courseinfoCollection;
    }

    public void setCourseinfoCollection(Collection<Courseinfo> courseinfoCollection) {
        this.courseinfoCollection = courseinfoCollection;
    }

    @XmlTransient
    public Collection<Users> getUsersCollection() {
        return usersCollection;
    }

    public void setUsersCollection(Collection<Users> usersCollection) {
        this.usersCollection = usersCollection;
    }

    @XmlTransient
    public Collection<Studentoutcome> getStudentoutcomeCollection() {
        return studentoutcomeCollection;
    }

    public void setStudentoutcomeCollection(Collection<Studentoutcome> studentoutcomeCollection) {
        this.studentoutcomeCollection = studentoutcomeCollection;
    }

    @XmlTransient
    public Collection<Peo> getPeoCollection() {
        return peoCollection;
    }

    public void setPeoCollection(Collection<Peo> peoCollection) {
        this.peoCollection = peoCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (identifier != null ? identifier.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Degreeprogram)) {
            return false;
        }
        Degreeprogram other = (Degreeprogram) object;
        if ((this.identifier == null && other.identifier != null) || (this.identifier != null && !this.identifier.equals(other.identifier))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Degreeprogram[ identifier=" + identifier + " ]";
    }

    @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        List<List<GeneralEntity>> associated = new ArrayList();
        associated.add((List) this.usersCollection);
        return associated;
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        if (associated.equals(Users.class.getSimpleName())) {
            return (List) this.usersCollection;
        } else if (associated.equals(Peo.class.getSimpleName())) {
            return (List) this.peoCollection;
        } else if (associated.equals(Studentoutcome.class.getSimpleName())) {
            return (List) this.studentoutcomeCollection;
        }
        return null;
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void testAddClass(GeneralEntity ge) {
        if (ge instanceof Users) {
            this.usersCollection.add((Users) ge);
        } else if (ge instanceof Courseinfo) {
            this.courseinfoCollection.add((Courseinfo) ge);
        } else if (ge instanceof Survey) {
            this.surveyCollection.add((Survey) ge);
        }
    }

    @Override
    public void removeClass(GeneralEntity ge) {
        if (ge instanceof Users) {
            this.usersCollection.remove((Users) ge);
        } else if (ge instanceof Courseinfo) {
            this.courseinfoCollection.remove((Courseinfo) ge);
        } else if (ge instanceof Survey) {
            this.surveyCollection.remove((Survey) ge);
        }
    }

    @Override
    public String getIdentifier2() {
        return this.identifier;
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    @Override
    public Object getPK() {
        return this.identifier;
    }
}
